import json
import execjs
import requests

headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Connection": "keep-alive",
    "Referer": "https://jzsc.mohurd.gov.cn/data/company",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
    "accessToken;": "",
    "sec-ch-ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "timeout": "30000",
    "v": "231012"
}
cookies = {
    "Hm_lvt_b1b4b9ea61b6f1627192160766a9c55c": "1752041998",
    "Hm_lpvt_b1b4b9ea61b6f1627192160766a9c55c": "1752041998",
    "HMACCOUNT": "2F6590DA41E80662"
}
url = "https://jzsc.mohurd.gov.cn/APi/webApi/dataservice/query/comp/list"
count = 0
url_list = []
for page in range(30):
    params = {
        "pg": f"{page}",
        "pgsz": "15",
        "total": "450"
    }
    response = requests.get(url, headers=headers, cookies=cookies, params=params)

    with open('建筑市场.js', 'r', encoding='utf-8') as f:
        js_code = execjs.compile(f.read())
    json_str = js_code.call("b", response.text)

    json_data = json.loads(json_str)
    data_list = json_data['data']["list"]

    for data in data_list:

        count += 1
        id = data['QY_ID']
        company = data['QY_NAME']
        link = f"https://jzsc.mohurd.gov.cn/data/company/detail?id={id}"
        url_list.append((company, link))
        print(page, count, id, company, link)

print(url_list)

